'use strict';

stareal
    .controller("MyController", function ($scope, $api, localStorageService,$alert) {
        $scope.mypage = 4;
        $scope.bellyremain;
        $scope.user = localStorageService.get("user");
        var h=$(window).height()+"px";
         $("#myIndex_container").height(h);
         // if($scope.user==undefined||$scope.user==null||$scope.user==''){
             $api.get("app/login/userinfo/retrieve", null, true)
                 .then(function (ret) {
                     $scope.user = ret.data;
                   localStorageService.set('user',ret.data);
                 });
         // }
        //
        $scope.getAbtainAidBar=function(){//app/activity/abtainAidBar  //获取应援
            // 分类列表
            $api.get("app/activity/abtainAidBar",{}, true)
                .then(function(ret){
                    $scope.abtainAidBar=ret;
                });
        }
        if(!localStorageService.get('token')){
            var data={};
            data.count=0;
            $scope.abtainAidBar=data;
        }else{
            $scope.getAbtainAidBar();
        }
        $scope.callphone= function (){
            window.location.href = "tel:400-8798613";
        }
        //连续签到可获得贝里
        $api.post("app/member/checkin/getCheckTips",{},true)
            .then(function (ret) {
                $scope.daybeily = ret.data;
            });
        $scope.member_icon= "vip0";
        $scope.sign_state = localStorageService.get("sign-state")
        //获取会员信息
        $api.get("app/member/index/retrieve",{},true)
            .then(function (ret) {
                $scope.level_name = ret.data.level_name
                $scope.member = ret.data.level;
                if($scope.member==1||$scope.member==2){
                    $scope.member_icon= "vip0";
                }else if($scope.member==3||$scope.member==4){
                    $scope.member_icon= "vip1";
                }else if($scope.member==5||$scope.member==6){
                    $scope.member_icon= "vip2";
                }else{
                    $scope.member_icon= "vip3";
                }
                $scope.totalvalue=ret.data.up_value+ret.data.value; //该等级需要的总积分
                $scope.up_value=ret.data.up_value;
                $scope.value=ret.data.value;

            })
        $scope.sign = function (bellyremain,todaybeily) {  //签到向下传播
            $scope.$broadcast('to-child');
            $scope.bellyremain = parseInt(bellyremain)+parseInt(todaybeily);
            localStorageService.set("beili",$scope.bellyremain);
            $scope.sign_state = 2;
        }
        $scope.bartotla=function(total,count){
            var bar=(count/total*100).toFixed(0);
            $scope.barstyle = {
                "width":bar+'%',
                "background":"#f5003a"
            }
            return $scope.barstyle;
        }
        $scope.bartotla0=function(total,count){
            var bar=(count/total*100).toFixed(0);
            $scope.barstyle0 = {
                "left":bar+'%' ,
            }
            return $scope.barstyle0;
        }
    //  我的积分商城  goToShop
    //     $scope.goToShop=function(){
    //         $api.get("app/duiba/index",{shop:1},true)
    //             .then(function (ret) {
    //                 var data=ret.data;
    //                 console.log(data);
    //                 var link=data.url;
    //                console.log(link);
    //                 window.location.href=link;
    //                 //window.open('https://activity.m.duiba.com.cn/chome/index?from=login&spm=53694.1.1.1','_blank');
    //             })
    //     }
    });